<?php require_once(BASEPATH.'application/controllers/validaciones.php');
//Cliente
class bmov extends validaciones {
	
	var $titulo;

	function bmov(){
		parent::Controller(); 
		$this->load->library("rapyd");
		$this->load->library('pi18n');
		$this->titulo=$this->datasis->traevalor('TITULO4');
	}

	function index(){
		redirect("ventas/bmov/filteredgrid");
	}
	function filteredgrid(){
		
		$this->rapyd->load("datafilter","datagrid2");
		$this->rapyd->uri->keep_persistence();
				
		//IF(formap='EF','EFECTIVO','CHEQUE')		
		$filter = new DataFilter("Buscar y Filtrar Movimientos de Bancos");
        $select=array('a.usuario','c.cajero as caj','clipro','numero','idabono','a.id as id','a.banco','a.referencia','monto','fecha',
		'conciliado','observacion',"CONCAT_WS('-',a.cajero,c.nombre)AS cajero",'b.descrip as nombre','IF(clipro="C","INGRESO",if(clipro="P","EGRESO","TRANSFERENCIA RECIBIDA")) as clipro');
		$filter->db->select($select);
		$filter->db->from('bmov AS a');
		$filter->db->join('bancos AS b' ,'a.banco=b.codigo');
        $filter->db->join('cajero AS c' ,'a.cajero=c.cajero','LEFT');
        //$filter->db->join('formap AS d' ,'a.formap=d.formap','LEFT');
        $filter->db->orderby('nombre');
        		
        $ano=date("Y");
        $mes=date("m");
                
        $filter->fechad = new dateonlyField('Desde', 'fechad','d/m/Y');
		$filter->fechah = new dateonlyField('Hasta', 'fechah','d/m/Y');
		$filter->fechah->size=$filter->fechad->size=12;
		$filter->fechah->operator='<=';
        $filter->fechad->insertValue = date("Y-m-d", mktime(0, 0, 0,1, 1, $ano));
        $filter->fechah->insertValue = date("Y-m-d"); 
		$filter->fechad->clause  =$filter->fechah->clause ='where';
		$filter->fechad->db_name =$filter->fechah->db_name='a.fecha';
		$filter->fechad->operator='>=';
		        
        $filter->formap = new dropdownField("Tipo", "a.formap");
        $filter->formap->option("","Todos");
		$filter->formap->style='width:300px;';
        $filter->formap->options("SELECT formap,nombre FROM formap ORDER BY nombre");
        
        $filter->banco = new dropdownField("Banco", "a.banco");
		$filter->banco->style='width:300px;';
        $filter->banco->option("","Todos");
		$filter->banco->options("SELECT codigo,CONCAT(codigo,'-',descrip)descrip FROM serier ORDER BY codigo" );
		$filter->banco->group = "Informaci&oacute;n de Recepci&oacute;n";
        
        $filter->cajero = new dropdownField("Cajero", "a.cajero");
		$filter->cajero->style='width:300px;';
        $filter->cajero->option("","Todos");
		$filter->cajero->option("1","ADMINISTRADORA 1");
		$filter->cajero->option("2","ADMINISTRADORA 2");
		$filter->cajero->group = "Informaci&oacute;n de Recepci&oacute;n";
		
		$filter->categoria = new dropdownField("Categoria", "a.clipro");
        $filter->categoria->option("","Todos");
        $filter->categoria->option("C","INGRESO");
        $filter->categoria->option("P","EGRESO");
        $filter->categoria->option("T","TRANSFERENCIA RECIBIDA");
		$filter->categoria->style='width:300px;';
		
		$filter->observacion = new inputField('Observaci&oacute;n', 'observacion');
		$filter->observacion->size = 20;
		
		$filter->numero = new inputField('N&uacute;mero', 'numero');
		$filter->numero->size = 20;
		
		$filter->monto = new inputField('Monto', 'monto');
		$filter->monto->size = 20;
        	
		$filter->buttons("reset","search");
		$filter->build("dataformfiltro");
        
        //$uri = anchor("ventas/bmov/dataedit/show/<#id#>","<#banco#>-<#numero#>");
        
		$grid = new DataGrid2("Resultado");
		$grid->order_by("numero","DESC");
        $grid->agrupar(" ",'nombre');
        $grid->use_function('formato');
        $grid->use_function('modify');
		$grid->per_page=8;
		
		function formato($clipro,$banco,$numero,$cajero){
			
			$atts = array(
				'width'      => '800',
				'height'     => '600',
				'scrollbars' => 'yes',
				'status'     => 'yes',
				'resizable'  => 'yes',
				'screenx'    => '0',
				'screeny'    => '0'
			);
			
			
			if($cajero!='2'){
			//Muestra formato segun origen
				
                if($clipro=='INGRESO'){
                    
                    $uri_2  = anchor_popup("formatos/ver/ABONO/AB/$banco/$numero",img(array('src'=>'images/pdf_logo.gif','border'=>'0','alt'=>'Ver Html','height'=>'15','title'=>'Ver Html')),$atts);
                    $uri_2 .= anchor_popup("formatos/verhtml/ABONO/AB/$banco/$numero",img(array('src'=>'images/html_icon.gif','border'=>'0','alt'=>'Ver Pdf','height'=>'15','title'=>'Ver Pdf')),$atts);
                
                }else{
    
                    $uri_2  = anchor_popup("formatos/ver/PAGO/AB/$banco/$numero",img(array('src'=>'images/pdf_logo.gif','border'=>'0','alt'=>'Ver Html','height'=>'15','title'=>'Ver Html')),$atts);
                    $uri_2 .= anchor_popup("formatos/verhtml/PAGO/AB/$banco/$numero",img(array('src'=>'images/html_icon.gif','border'=>'0','alt'=>'Ver Pdf','height'=>'15','title'=>'Ver Pdf')),$atts);
                }
                
            }else{
                
                    $uri_2  = anchor_popup("formatos/ver/TRANSF/$banco/$numero",img(array('src'=>'images/pdf_logo.gif','border'=>'0','alt'=>'Ver Html','height'=>'15','title'=>'Ver Html')),$atts);
                    $uri_2 .= anchor_popup("formatos/verhtml/TRANSF/$banco/$numero",img(array('src'=>'images/html_icon.gif','border'=>'0','alt'=>'Ver Pdf','height'=>'15','title'=>'Ver Pdf')),$atts);

            }
			
			return($uri_2);
		}
		
		function modify($idabono,$banco,$numero,$id,$clipro,$cajero){
			
			$atts = array(
				'width'      => '1150',
				'height'     => '600',
				'scrollbars' => 'yes',
				'status'     => 'yes',
				'resizable'  => 'yes',
				'screenx'    => '0',
				'screeny'    => '0'
			);
			
			//Muestra formato segun origen
				
			IF($clipro=='INGRESO'){
                
				$num='R'.$banco.'-'.$numero; 
				
			
			}ELSE{
                
               IF($clipro=='EGRESO'){ 
				
				$num='G'.$banco.'-'.$numero; 
                
               }ELSE{
                   
                $num='T'.$banco.'-'.$numero;     
                   
               }   
			}
			
			if($cajero=='1'){
				
				if($clipro=='INGRESO'){
				
					$uri = anchor_popup("ventas/smov/dataedit/show/$idabono","$num",$atts);
				
				}else{
					
					$uri = anchor_popup("finanzas/sprm/dataedit/show/$idabono","$num",$atts);
				
				}
			
			}else{
				
				$uri = anchor_popup("ventas/bmov/dataedit/show/$id","$num",$atts);
			
			}
			
			return($uri);
		}
        
        $grid->column('Acci&oacute;n',"<formato><#clipro#>|<#banco#>|<#numero#>|<#cajero#></formato>"    ,"align='center'");		
        $grid->column_orderby("Fecha"               ,"<dbdate_to_human><#fecha#></dbdate_to_human>",'fecha'   ,"align='center'");
        $grid->column_orderby("N&uacute;mero"       ,'<modify><#idabono#>|<#banco#>|<#numero#>|<#id#>|<#clipro#>|<#caj#></modify>' ,'numero',"align='center'");
        $grid->column("N&uacute;mero de Operaci&oacute;n"       ,"referencia"                 ,"align='left'");
        $grid->column("Monto"               ,"<nformat><#monto#></nformat>"                   ,"align='right'");
        $grid->column("Cajero"              ,"cajero"                                         ,"align='center'");
        $grid->column("Usuario"              ,"usuario"                                         ,"align='center'");
        //$grid->column("Recepcion"           ,"<dbdate_to_human><#recepcion#></dbdate_to_human>","align='center'");
        //$grid->column("Conciliado"          ,"conciliado"                                   ,"align='center'");
        $grid->column("Movimiento"     ,"clipro"                                         ,"align='left'");
        $grid->column("Observaci&oacute;n"  ,"observacion"                                    ,"align='left'");
        
		$grid->totalizar('monto');
		
        $grid->add('ventas/bmov/dataedit/create','Nuevo Registro');
		$grid->build('datagridST');
		//echo $grid->db->last_query();
		
		$cana=$grid->recordCount;
		$grid=$grid->output;
		
		$style ='
		<style type="text/css">
		.fakeContainer { /* The parent container */
		    margin: 5px;
		    padding: 0px;
		    border: none;
		    width: 1000px; /* Required to set */
		    height: 400px; /* Required to set */
		    overflow: hidden; /* Required to set */
		}
		</style>	
		';

		$data['style']   = $style;
		$data['style']  .= style('superTables.css');
		
		IF($cana<=0){
			$data['content'] = '<div align="center">Ningun Resultado Obtenido</div>';	
		}ELSE{
			$data['content'] = $grid;		
		}

		//$data['content'] = $grid;
	
		$data['content'].= $this->pi18n->fallas();
		$data['filtro']  = $filter->output;

		$data['title']   = heading("Movimiento de Bancos");
		$data['script']  = script('jquery.js');
		$data["script"] .= script('superTables.js');
		$data['head']    = $this->rapyd->get_head();

		$this->load->view('view_ventanas', $data);
	}
	 function dataedit(){
		
		$this->rapyd->load('dataobject','datadetails');
		
		$this->db->query("DROP TABLE IF EXISTS sprv2");
		$this->db->query("CREATE TABLE sprv2 SELECT * FROM sprv");
		$this->db->query("DROP TABLE IF EXISTS scli2");
		$this->db->query("CREATE TABLE scli2 SELECT * FROM scli");
		
		 $modbus_sprv=array(
			'tabla'   =>'sprv2',
			'columnas'=>array(
	                'rif'=>'RIF',		
                'proveed' =>'C&oacute;digo Proveedor',
                'nombre'=>'Nombre'),
			'filtro'  =>array('rif'=>'RUC','nombre'=>'Nombre'),
			'retornar'=>array(
                'proveed'=>'bproveed',
                'rif'=>'brif',
                'nombre'=>'bnombre'),
                'p_uri'   => array(4=>'<#i#>'),
			'titulo'  =>'Buscar Proveedor');

		$boton2=$this->datasis->p_modbus($modbus_sprv);	
		
		$modbus_scli=array(
			'tabla'   =>'scli2',
			'columnas'=>array(
	            'rifci'=>'RIF',		
                'cliente' =>'C&oacute;digo Cliente',
                'nombre'=>'Nombre'),
			'filtro'  =>array('rif'=>'RUC','nombre'=>'Nombre'),
			'retornar'=>array(
                'cliente'=>'bproveed',
                'rifci'=>'brif',
                'nombre'=>'bnombre'),
                'p_uri'   => array(4=>'<#i#>'),
			'titulo'  =>'Buscar Proveedor');

		$boton3=$this->datasis->p_modbus($modbus_scli);	
		
		$modbus_banco=array(
			'tabla'   =>'bancos',
			'columnas'=>array(
	            'rifb'=>'RIF',		
                'codigo' =>'C&oacute;digo Banco',
                'descrip'=>'Nombre'),
			'filtro'  =>array('rifb'=>'RUC','descrip'=>'Nombre'),
			'retornar'=>array(
                'codigo'=>'bproveed',
                'rifb'=>'brif',
                'descrip'=>'bnombre'),
                'p_uri'   => array(4=>'<#i#>'),
			'titulo'  =>'Buscar Banco');

		$boton4=$this->datasis->p_modbus($modbus_banco);			
		
		//echo $abono;
				
		 $modbus1=array(
			'tabla'   =>'sprv',
                'columnas'=>array(
                'rif'=>'RUF',		
                'proveed' =>'C&oacute;digo Proveedor',
                'nombre'=>'Nombre'),
			'filtro'  =>array('rif'=>'RUC','nombre'=>'Nombre'),
			'retornar'=>array(
				'rif' =>'ruc_<#i#>'),
			'p_uri'   => array(4=>'<#i#>'),
			'titulo'  => 'Buscar RUC'
		);
		
        $btn1=$this->datasis->p_modbus($modbus1,'<#i#>'); 
        
        $modbus2=array(
			'tabla'   =>'scli',
                'columnas'=>array(
                'rifci'=>'RUF',		
                'cliente' =>'C&oacute;digo Cliente',
                'nombre'=>'Nombre'),
			'filtro'  =>array('rif'=>'RUC','nombre'=>'Nombre'),
			'retornar'=>array(
				'rifci' =>'ruc_<#i#>'),
			'p_uri'   => array(4=>'<#i#>'),
			'titulo'  => 'Buscar RUC'
		);
		
        $btn2=$this->datasis->p_modbus($modbus2,'<#i#>');   
		
		$modbus=array(
			'tabla'   =>'cpla',
			'columnas'=>array(
				'cuenta'  =>'Cuenta',
				'descrip' =>'Descripci&oacute;n',
				'ajuste'  => 'Llevar Ajuste',
				'contrapartida'  => 'Contrapartida',
				'clase'  => 'Clase',
				'costo'  => 'Costo',
				'tercero'  => 'Tercero',
				'extranjeria'  => 'Extranjeria'
				),
			'filtro'  =>array('cuenta'  =>'Cuenta','descrip'=>'Descripci&oacute;n'),
			'retornar'=>array(
				'cuenta' =>'cuenta_<#i#>',
				'descrip'=>'desca_<#i#>',
				),
			'p_uri'   => array(4=>'<#i#>'),
			'titulo'  => 'Buscar Cuenta'
		);
		
        $btn=$this->datasis->p_modbus($modbus,'<#i#>');	
		
		$do = new DataObject('bmov');
		$do->rel_one_to_many('itbmov', 'itbmov', 'id');
				
		$edit = new DataDetails('Movimientos de Banco', $do);
		$edit->back_url = site_url('finanzas/bmov/filteredgrid');
		$edit->set_rel_title('itbmov','Cuenta <#o#>');
		
		$edit->back_url = site_url("ventas/bmov/filteredgrid");
		    		
		$script ='
		$(function() {
			$(".inputnum").numeric(".");
		});
		
		';
		
		$edit->script($script, "create");
		$edit->script($script, "modify");
		
        $edit->pre_process('insert','_pre_insert');
        $edit->post_process('insert','_post_insert');
        
        $edit->pre_process('update','_pre_insert');
        $edit->post_process('update','_post_insert');

        $edit->pre_process('delete','_pre_delete');
		        
        $edit->usuario  = new autoUpdateField('usuario', $this->session->userdata('usuario'), $this->session->userdata('usuario'));
		
        $edit->id = new hiddenField(" ", 'id');
        $edit->cajero = new hiddenField(" ", 'cajero');
        $id=$edit->_dataobject->get("id");
        
        $edit->bproveed = new inputField("C&oacute;digo", "bproveed");
		$edit->bproveed->size = 7;
		$edit->bproveed->maxlength=5;
        $edit->bproveed->append($boton2.' P '.$boton3.' C'.$boton4.' B');
        $edit->bproveed->rule= "required";
        $edit->bproveed->readonly  = true;
		
		$edit->bnombre = new inputField("Nombre", "bnombre");
		$edit->bnombre->size =  40;
		$edit->bnombre->maxlength=80;
        $edit->bnombre->readonly  = true;
    
		$edit->brif = new inputField("RUC", "brif");
		$edit->brif->size =  20;
		$edit->brif->maxlength=20; 
        $edit->brif->readonly  = true;
        
        $edit->fecha = new DateonlyField('Fecha', 'fecha','Y-m-d');
		$edit->fecha->rule = 'required';
        $edit->fecha->rule= "callback_cambio";
		$edit->fecha->size = 12;
		$edit->fecha->insertValue = date("Y-m-d");
		                      				        
        $edit->banco = new dropdownField("Banco", "banco");
		$edit->banco->style='width:200px;';
		$edit->banco->option("","Seleccione una Opci&oacute;n");
		$edit->banco->options("SELECT codigo, descrip FROM serier ORDER BY codigo" );
		$edit->banco->rule= "callback_chexistecomp";
		$edit->banco->onchange = "tipod();";
		//$edit->banco->onchange = "numegreso();";
		$edit->banco->mode="autohide";
		
		$edit->ccosto = new  dropdownField ('Centro de Costo', 'ccosto');
        $edit->ccosto->option("0001","ADMINISTRACI&Oacute;N");
		$edit->ccosto->option('0002',"OPERACI&Oacute;N");
		$edit->ccosto->option('0003','IMPORTACI&Oacute;N'); 
		$edit->ccosto->style='width:300px;';    
				
		$edit->numero = new inputField('N&uacute;mero', 'numero');
		$edit->numero->size = 12;
		$edit->numero->maxlength=11;
		$edit->numero->mode="autohide";
		$edit->numero->in="banco";
				        
        $edit->clipro = new dropdownField("Movimiento de Banco por", "clipro");
        $edit->clipro->option("P","EGRESO");
        $edit->clipro->option("C","INGRESO");
        $edit->clipro->onchange = "tipod();";
        if(($edit->_status=='show')){
        $edit->clipro->option("T","TRANSFERENCIA RECIBIDA");
		}
        //$edit->clipro->onchange = "mcambio();";
        //$edit->clipro->option("O","OTROS");
        $edit->clipro->style='width:300px;';	
        	
        $edit->formap = new dropdownField("Tipo de Transacci&oacute;n", "formap");
		$edit->formap->size = 15;
		$edit->formap->style='width:300px;';
        $edit->formap->options("SELECT formap,CONCAT(formap,'-',nombre)nombre FROM formap ORDER BY nombre");
  
		$edit->referen = new inputField('N&uacute;mero de Operaci&oacute;n', 'referencia');
		$edit->referen->size = 20;
		$edit->referen->rule = 'required';
		$edit->referen->maxlength=50;
        
        $edit->cuenta2 = new inputField('Cuenta', 'cuenta');
		$edit->cuenta2->size     = 12;
		$edit->cuenta2->rule     = 'required';
		//$edit->cuenta->append($btn);
		$edit->cuenta2->readonly  =true;
		$edit->cuenta2->when=array('show');
		
		$edit->tipo2 = new  dropdownField ('Tipo de Documento', 'tipo2');
        $edit->tipo2->db_name='tipo_doc';
        $edit->tipo2->option("OT","OTROS MOVIMIENTOS DE BANCO");
        //$edit->tipo2->option("AB","PAGO DE PROVEEDOR");
        $edit->tipo2->option('AP',"ADELANTO DE PLANILLAS");
        $edit->tipo2->option('PP',"PRESTAMOS PERSONAL");
        if($edit->_status!='create'){
            
            $edit->tipo2->option('AN',"ANTICIPO DE PROVEEDOR");
            $edit->tipo2->option('EC',"ENTREGAS A RENDIR CUENTA");
        }
        
		$edit->tipo2->style='width:300px;'; 
		
        $edit->monto = new inputField("Monto de Operaci&oacute;n", 'monto');
        $edit->monto->css_class ='inputnum';
		$edit->monto->size      = 20;
		$edit->monto->when=array('show');
		
		$edit->montos = new inputField("Monto de Operaci&oacute;n", 'montos');
        $edit->montos->css_class ='inputnum';
		$edit->montos->size      = 20;
		$edit->montos->when=array('show');
		
		$edit->montod = new inputField("Monto de Operaci&oacute;n", 'montod');
        $edit->montod->css_class ='inputnum';
		$edit->montod->size      = 20;
		$edit->montod->when=array('show');
        		
	    $edit->moneda = new dropdownField("Moneda", "moneda");
		$edit->moneda->style='width:300px;';
		$edit->moneda->option("","Seleccione la moneda" );
		$edit->moneda->options("SELECT codigo,descrip FROM moneda ORDER BY codigo");
		$edit->moneda->rule = 'required';
		$edit->moneda->group = "Precios";
		//$edit->moneda->when=array('show');
		
		$fechac=$this->datasis->dameval("SELECT cambio FROM cambio WHERE fecha=CURDATE()");
		$edit->cambio = new inputField("Cambio", 'cambio');
		$edit->cambio->css_class ='inputnum';
		$edit->cambio->size      = 12;
		$edit->cambio->insertValue=$fechac;
		$edit->cambio->onclick = "cfecha();";
		$edit->cambio->rule = 'required';
			        		
		$edit->cajero = new dropdownField("Cajero", "cajero");
		$edit->cajero->style='width:200px;';
        $edit->cajero->option("2","ADMINISTRADORA");
		
		$edit->condi1 = new inputField("Observaci&oacute;n", 'observacion');
		$edit->condi1->size = 40;
		$edit->condi1->maxlength=30;
		$edit->condi1->rule = 'required';
		
		//**************************
		//  Campos para el detalle
		//**************************
		$edit->docu = new dropdownField('Documento <#o#>', 'docu_<#i#>');
		$edit->docu->db_name  = 'docu';
		$edit->docu->options("SELECT codigo,descrip FROM tpagos");
		$edit->docu->rel_id   = 'itbmov';
		$edit->docu->style    = 'width:100%';
		
		$edit->cuenta = new inputField('Cuenta <#o#>', 'cuenta_<#i#>');
		$edit->cuenta->size     = 12;
		$edit->cuenta->maxlength= 10;
		$edit->cuenta->readonly  = true;
		$edit->cuenta->db_name  = 'cuenta';
		$edit->cuenta->rel_id   = 'itbmov';
		//$edit->cuenta->rule     = 'required';
		$edit->cuenta->append($btn);
		

		$edit->desca = new inputField('Descripci&oacute;n <#o#>', 'desca_<#i#>');
		$edit->desca->db_name='desca';
		$edit->desca->rel_id='itbmov';
		$edit->desca->rule = 'strtoupper';
		$edit->desca->size    = 35;
		
		$edit->ruc = new inputField('RUC <#o#>', 'ruc_<#i#>');
		$edit->ruc->db_name='ruc';
		$edit->ruc->rel_id='itbmov';
		$edit->ruc->rule = 'strtoupper';
        $edit->ruc->append($btn1.' P');
        $edit->ruc->append($btn2.' C');
        //$edit->ruc->insertValue = $rif;
		$edit->ruc->size    = 11;
		$edit->ruc->maxlength= 11;
		
		$edit->tipo = new dropdownField('Tipo <#o#>', 'tipo_<#i#>');
		$edit->tipo->db_name  = 'tipo';
		$edit->tipo->option("","");
		$edit->tipo->option("D","D");
		$edit->tipo->option("C","C");
		$edit->tipo->rel_id   = 'itbmov';
		$edit->tipo->rule     = 'positive';
		$edit->tipo->autocomplete=false;
		$edit->tipo->onchange ='importe(<#i#>)';
		$edit->tipo->style    = 'width:100%';
		
		$edit->importe = new inputField('Importe <#o#>', 'importe_<#i#>');
		$edit->importe->db_name='importe';
		$edit->importe->size=12;
		//$edit->importe->readonly=true;
        //$edit->importe->rule = 'required';
		$edit->importe->css_class='inputnum';
		$edit->importe->rel_id   ='itbmov';
		$edit->importe->onkeyup  ='importe(<#i#>)';
		
		$edit->creditos = new inputField('creditos <#o#>', 'creditos_<#i#>');
		$edit->creditos->db_name='creditos';
		$edit->creditos->size=12;
		$edit->creditos->css_class='inputnum';
		$edit->creditos->rel_id   ='itbmov';
		$edit->creditos->readonly=true;
		$edit->creditos->onkeyup  ='importe(<#i#>)';
        
        $id=$edit->_dataobject->get("id");
        $clipro=$edit->_dataobject->get("clipro");
        $doc='';
        if($clipro=='P'){$doc='G';}else{$doc='R';}
        
        $accion="javascript:window.location='".site_url("ventas/bmov/dataedit/create")."'";  
        $edit->button_status('btn_bmov','Nuevo Registro',$accion,'TR','show');
               
        $edit->buttons('delete','modify','save', 'undo', 'add_rel','back'); 	
        $edit->build();
                              
		$conten['form']  =&  $edit;
		$data['content'] = $this->load->view('view_bmov', $conten,true);
		$data['title']   = heading($doc.$edit->banco->value.'-'.$edit->numero->value);
		$data['style']  = style('redmond/jquery-ui-1.8.1.custom.css');
		
		$data['script']  = script('jquery.js');
		$data['script'] .= script('jquery-ui.js');
		$data['script'] .= script('plugins/jquery.numeric.pack.js');
		$data['script'] .= script('plugins/jquery.numeric.pack.js');
		$data['script'] .= script('plugins/jquery.floatnumber.js');
		$data['script'] .= script('nformat.js');

		$data['head']    = $this->rapyd->get_head();
		$this->load->view('view_ventanas', $data);
			
	}
    function _pre_delete($do){
        
        $id=$do->get('id');
        $banco=$do->get('banco');
        
        $this->db->query("DELETE FROM bmov WHERE idabono='$id' and clipro='T'");
        
        $banco=$do->get('banco');
        $numero=$do->get('numero');
        
        logusu('bmov',"MOVIMIENTO $banco-$numero ELIMINADO");
           
    }        
              
 function _pre_insert($do){
         
        $fecha   =$do->get('fecha');
        $serie   =$do->get('banco');
        $cambio  =$do->get('cambio');
        $numero  =$do->get('numero');
        $clipro  =$do->get('clipro');
             
        $cuenta=$this->datasis->dameval("SELECT cuenta FROM bancos WHERE codigo='$serie'");
        $moneda=$this->datasis->dameval("SELECT moneda FROM bancos WHERE codigo='$serie'");
        
        $tipo2=$do->get('tipo2');
                 
        $do->set('moneda',$moneda);
        $do->set('cuenta',$cuenta);
        $do->set('cajero','2');
                
        $tsoles  = $this->input->post('smonto');
        $tdolar  = $this->input->post('dmonto');
            
        if(empty($cambio)){
            
            $cambio=$this->datasis->dameval("SELECT cambio FROM cambio WHERE fecha='$fecha'");
            $do->set('cambio',$cambio);
        }
              
        //echo $tsoles;
        //echo $tdolar;
        if (($tdolar<=0)||($tsoles<=0)){
			echo "<span style='color:red' align='center'>Debe ingresar una cantidad mayor a 0,00, Movimiento DESCUADRADO</span>";
			$this->validation->set_message('pre_insert',"Error al ingresar informacion , debe registrar un pago mayor a 0,00");
			return FALSE;
		}else {
			
			IF($moneda=='01'){
                $monto=$tsoles;
            }else{
                $monto=$tdolar;
            }
            
			$do->set('monto',$monto);
			$do->set('montos',$tsoles);
			$do->set('montod',$tdolar);
			return TRUE;
		}
               
        
        
        //$do->set('recepcion','CURDATE()');
        logusu('bmov',"MOVIMIENTO $serie-$numero CREADO");
        
    }
    function _post_insert($do){
        
        $formap=$do->get('formap');
        $referen=$do->get('referen');
        $fecha=$do->get('fecha');
        $usuario=$this->session->userdata['usuario'];
        $id=$do->get('id');
        $numero=$do->get('numero');

        if($formap=='0003'){
			
			$this->db->query("DELETE FROM bmov WHERE idabono='$id' and clipro='T'");	
			$mSQL=$this->db->query("SELECT * FROM itbmov as a WHERE a.id='$id'");
				
			foreach($mSQL->result() as $items ){
				
				$banco=$this->datasis->dameval("SELECT codigo FROM bancos WHERE cuenta='$items->cuenta'");
				
				$this->db->query("INSERT INTO bmov(idabono,banco,numero,formap,referencia,monto,fecha,observacion,cajero,usuario,clipro)
                                            VALUES('$id','$banco',LPAD('$items->idt',11,'0'),'$formap','$referen','$items->importe','$fecha','TRANSFERENCIA RECIBIDA DE G$banco-$numero','1','$usuario','T')");

			
			}                   
        }
    }
	function chexistecomp(){
		
		$numero =$this->input->post('numero');
		$serie  =$this->input->post('banco');
		$clipro =$this->input->post('clipro');
		
		$numero =str_pad($numero, 11, "0", STR_PAD_LEFT);
		$serie  =str_pad($serie, 3, "0", STR_PAD_LEFT);
		
		$chek=$this->datasis->dameval("SELECT COUNT(*) FROM bmov  WHERE banco='$serie' AND clipro='$clipro' AND numero='$numero'");
		
		if ($chek){
			$this->validation->set_message('chexistecomp',"El numero de comprobante $numero ya se encuetra registrado");
			return FALSE;
		}else {
		 return TRUE;
		}
		
	}
}
?>
